package Servlet.manager;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

public class ManagerServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter pw=response.getWriter();
        //表格修饰样式
        pw.print("<link rel=\"stylesheet\" href=css/table.css type=\"text/css\">");
        pw.print("<script type=\"text/javascript\" src=\"js/jquery-3.4.1.js\"></script>\n" +
                "    <script type=\"text/javascript\">\n" +
                "        $(function () {\n" +
                "            $.ajax({url:\"json\",dataType:\"json\",success:function (resp) {\n" +
                "                    $(\"#sel\").empty();\n" +
                "                    $(\"#sel\").append(\"<option>请选择用户名</option>\")\n" +
                "                    $(resp).each(function (index,element) {\n" +
                "                        $(\"#sel\").append(\"<option>\"+element.username+\"</option>\");\n" +
                "                    })\n" +
                "                }})\n" +
                "                    clii=function () {\n" +
                "                        if ($(\"#sel\").val()!==\"请选择用户名\"&&$(\"#str\").val()){\n" +
                "                            document.getElementById(\"bt\").submit();\n" +
                "                    }\n" +
                "                }"+
                "        })\n" +
                "    </script>");
        pw.print(" <form action=\"/user/maninsert\" >\n" +
                "            <table align=\"center\" border=\"1px\">\n" +
                "            <tr>\n" +
                "                <th>用户类型</th>\n" +
                "                <th>用户名</th>\n" +
                "                <th>密码</th>\n" +
                "                <th>性别</th>\n" +
                "                <th>电话</th>\n" +
                "                <th>地址</th>\n" +
                "                <th>摄像头数量</th>\n" +
                "            </tr>\n" +
                "                <tr>\n" +
                "                    <td>" +
                "                        <select name=\"user\">\n" +
                "                            <option  value=\"public\" selected>public</option>\n" +
                "                        </select></td>\n" +
                "                    <td><input  style=\"width: 70px\"  type=\"text\" required name=\"username\"  pattern=\"^[A-Za-z0-9]{6,10}$\"></td>\n" +
                "                    <td><input style=\"width: 80px\" type=\"text\" required  name=\"password\" pattern=\"^.{6,12}$\"></td>\n" +
                "                    <td>\n" +
                "                        男<input  type=\"radio\"  name=\"sex\" value=\"男\" checked>\n" +
                "                        女<input name=\"sex\" type=\"radio\" value=\"女\" >\n" +
                "                    </td>\n" +
                "                    <td><input style=\"width: 80px\" type=\"text\" required  name=\"phone\" pattern=\"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$\"></td>\n" +
                "                    <td><input style=\"width: 80px\" type=\"text\" required name=\"address\" ></td>\n" +
                "                    <td><input style=\"width: 40px\" type=\"text\" required name=\"num\" pattern=\"^[0-9]*$\"></td>\n" +
                "                    <td><input class=\"mybt\" type=\"submit\" value=\"添加用户\"></td>\n" +
                "                </tr>\n" +
                "            </table>\n" +
                "        </form>");
        pw.print(" <form action=\"/user/caminsert\" id=\"bt\">\n" +
                "        <br><br>\n" +
                "        <table border=\"1px\" align=\"center\">\n" +
                "            <tr>\n" +
                "                <th>用户名</th>\n" +
                "                <th>街道信息</th>\n" +
                "            </tr>\n" +
                "            <tr>\n" +
                "                <td>\n" +
                "                    <select name=\"username\" id=\"sel\" required>\n" +
                "                        <option>请选择用户名</option>\n" +
                "                    </select>\n" +
                "                </td>\n" +
                "                <td><input type=\"text\" required  name=\"street\" id=\"str\"></td>\n" +
                "                <td><input class=\"mybt\" type=\"button\" onclick=\"clii()\" value=\"保存\"></td>\n" +
                "            </tr>\n" +
                "        </table>\n" +
                "    </form>");
        pw.flush();
        pw.close();
    }
}
